﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using System.Reflection;
using IPlugin;

namespace Embedded_Sensor_Cloud
{
    public class Server
    {
        private TcpListener serverSocket;
        private PluginManager pluginManager;
        public Server()
        {
            serverSocket = new TcpListener(IPAddress.Any, 8080);
            pluginManager = new PluginManager();
            pluginManager.LoadPlugins();
        }
        public void Run()
        {
            while (true)
            {
                //listening
                serverSocket.Start();
                Socket so = serverSocket.AcceptSocket();
                Console.WriteLine("Neue Verbindung eingegangen...");
                ServerClientConnection scc = new ServerClientConnection(so, pluginManager);
                Thread t = new Thread(scc.Run);
                t.Start();
            }
        }

    }
}
